package com.hue.springbooteasyexcel.controller;

import com.alibaba.excel.EasyExcel;
import com.hue.springbooteasyexcel.domain.TbUser;
import com.hue.springbooteasyexcel.listener.ExcelListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @Author: 姚凤桥
 * @Date: 2022/4/12 14:33
 * @Description:
 */
@RestController
public class UserController {
    @Autowired
    private ExcelListener excelListener;

    @PostMapping("/import")
    public String userImport(MultipartFile file) throws IOException {
        EasyExcel easyExcel = new EasyExcel();
        easyExcel.read(file.getInputStream(), TbUser.class, excelListener).sheet().doRead();
        return "导入完成";
    }

    @GetMapping("/test")
    public String get() {
        return "test";
    }

}
